package com.arron.algorithm.leetcodetop100.二叉树;

import com.arron.algorithm.tree.TreeNode;

/**
 *
 * 98. 验证二叉搜索树
 */
public class ValidBST {


    public boolean isValidBST(TreeNode root) {

        return validBST(root,Long.MAX_VALUE,Long.MIN_VALUE);
    }

    public boolean validBST(TreeNode root,long upper,long lower){

        if (root == null){
            return  true;
        }

        if (root.val >= upper || root.val <= lower){
            return false;
        }
        return validBST(root.left,root.val,lower) && validBST(root.right,upper,root.val);
    }


}
